﻿namespace RefactorVariables
{
    using System;

    internal static class StatisticsProcessor
    {
        public static void PrintAllStatisticsFromArray(double[] array, int elementsCount)
        {
            Console.WriteLine(GetMaxValueFromArray(array, elementsCount));

            Console.WriteLine(GetMinValueFromArray(array, elementsCount));

            Console.WriteLine(GetAverageValueOfArrayElement(array, elementsCount));
        }

        public static double GetMaxValueFromArray(double[] arr, int indexOfLastButOneElement)
        {
            double maximumValue = double.MinValue;

            for (int i = 0; i < indexOfLastButOneElement; i++)
            {
                if (arr[i] > maximumValue)
                {
                    maximumValue = arr[i];
                }
            }

            return maximumValue;
        }

        public static double GetMinValueFromArray(double[] arr, int indexOfLastButOneElement)
        {
            double minimumValue = double.MaxValue;

            for (int i = 0; i < indexOfLastButOneElement; i++)
            {
                if (arr[i] < minimumValue)
                {
                    minimumValue = arr[i];
                }
            }

            return minimumValue;
        }

        public static double GetAverageValueOfArrayElement(double[] array, int indexOfLastButOneElement)
        {
            double elementsSum = 0;

            for (int i = 0; i < indexOfLastButOneElement; i++)
            {
                elementsSum += array[i];
            }

            int count = indexOfLastButOneElement;
            double averageValue = elementsSum / count;

            return averageValue;
        }
    }
}